<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<jsp:include page="../include/header.jsp" />
<script type="text/javascript" src="<c:url value='/htmlRes/js/datepicker/jquery.ui.core.js'/>"></script>
<script type="text/javascript" src="<c:url value='/htmlRes/js/datepicker/jquery.ui.datepicker.js'/>"></script>
<script type="text/javaScript">
<!--
	$(document).ready(function(){
		$( "#searchSdate" ).datepicker();
		$( "#searchEdate" ).datepicker();
	});
	
	function searchForm(){
		$('#listForm').attr('action', '<c:url value="/inven/useDrug.do"/>');
		$('#listForm').submit();
	}
	function excelDown(listCnt){
		if(listCnt == 0){
			alert('데이터가 없습니다.');
			return;
		}
		$('#listForm').attr('action', '<c:url value="/inven/useDrugExcelDown.do"/>');
		$('#listForm').submit();
	}
-->
</script>
<!-- contents s -->
<div class="container" id="container">
	<span class="round lt" style="">&nbsp;</span>
	<span class="round rt">&nbsp;</span>
	<span class="round lb">&nbsp;</span>
	<span class="round rb">&nbsp;</span>
	<div class="container_area">
		<h2 class="tit_h2">약품 사용 현황</h2>
			<jsp:include page="../include/navi.jsp" />
			<span class="ico_print"><a href="#print"  onclick="printPage('<c:url value="/common/printView.do" />');return false;"><img src="/htmlRes/images/ico_print.jpg" alt="인쇄버튼"></a></span>
			<div class="srch_wrap">
				<form name="listForm" id="listForm" method="post" action="<c:url value='/inven/useDrug.do'/>">
					<fieldset>
						<legend>키워드 검색 조회 영역</legend>
						<c:if test="${loginSessionInfo.admin }">
						<select id=searchServiceArea name="searchServiceArea" title="현장 검색" onchange="searchForm();">
							<option value="">전체</option>
							<c:forEach var="result" items="${serviceareaList }"  varStatus="status">
								<option value="${result.ssa_area_key }" <c:if test="${result.ssa_area_key eq searchVO.searchServiceArea}">selected="selected"</c:if>>${result.ssa_area_name }</option>
							</c:forEach>		
						</select>
						</c:if>
						<label for="searchSdate">기간 </label><input type="text" id="searchSdate" name="searchSdate" value="${searchVO.searchSdate }"/> - <input type="text" id="searchEdate" name="searchEdate" value="${searchVO.searchEdate }">
						<a href="<c:url value='/inven/useDrug.do'/>" onclick="searchForm();return false;" class="btn_srch">검색</a>
						<a href="<c:url value='/inven/useDrugExcelDown.do'/>" onclick="excelDown(${fn:length(resultList) });return false;" class="btn_exceldown">엑셀 다운로드</a>
					</fieldset>
				</form>
			</div>
			<c:set var="codeStrlength" value="4" />
			<c:set var="codeSize" value="${fn:length(codeList)+1 }"/>
			<c:forEach var="code" items="${codeList }">
				<c:set var="codeStrlength" value="${codeStrlength+fn:length(code.scc_code_name) }"/>
			</c:forEach>
			<c:set var="colSize" value="${100/codeStrlength }"/>
			<div class="table_wrap">
				<table summary="약품 사용량 현황 테이블 입니다" class="table_list">
					<caption>약품 사용 현황</caption>
					<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
						<col width="${colSize*4 }%" />
						<c:forEach var="code" items="${codeList }">
							<col width="${colSize*fn:length(code.scc_code_name)}%" />
						</c:forEach>
					</colgroup>
					<thead>
						<tr>
						<th>날짜</th>
					<c:forEach var="code" items="${codeList }">
						<th>${code.scc_code_name }</th>
					</c:forEach>
						</tr>
					</thead>
					<tbody>
					<c:forEach var="result" items="${resultList }" varStatus="status">
						<tr>
						<c:forEach var="resultMap" items="${result }" varStatus="status">
							<c:if test="${status.first }">
								<td>${resultMap.value }</td>
							</c:if>
							<c:if test="${!status.first }">
								<c:set var="useDrugVal" value="${resultMap.value }"/>
								<c:if test="${empty useDrugVal}"><c:set var="useDrugVal" value="0"/></c:if>
								<td><fmt:formatNumber value="${useDrugVal }" /></td>
							</c:if>
						</c:forEach>
						</tr>
					</c:forEach>
					<c:if test="${empty resultList }">
						<tr><td colspan="${codeSize+1 }">데이터가 없습니다</td></tr>
					</c:if>
					</tbody>
				</table>
			</div><!--//table_wrap-->
			<div class="table_wrap">
				<table summary="사용량 입고량 재고량 테이블 입니다" class="table_list">
					<caption>사용량 입고량 재고량</caption>
					<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
						<col width="${colSize*4 }%" />
						<c:forEach var="code" items="${codeList }">
							<col width="${colSize*fn:length(code.scc_code_name)}%" />
						</c:forEach>
					</colgroup>
					<thead>
						<tr>
							<th scope="col">통계</th>
							<c:forEach var="code" items="${codeList }">
								<th>${code.scc_code_name }</th>
							</c:forEach>
						</tr>
					</thead>
					<tbody>
						<c:forEach var="result" items="${resultSumList }">
						<tr>
							<c:forEach var="resultMap" items="${result }" varStatus="status">
								<c:if test="${status.first }">
									<td>${resultMap.value }</td>
								</c:if>
								<c:if test="${!status.first }">
									<c:set var="useDrugTotalVal" value="${resultMap.value }"/>
									<c:if test="${empty useDrugTotalVal}"><c:set var="useDrugTotalVal" value="0"/></c:if>
									<td><fmt:formatNumber value="${useDrugTotalVal }" /></td>
								</c:if>
							</c:forEach>
						</tr>
						</c:forEach>
					</tbody>
				</table>
			</div><!--//table_wrap-->
			
	</div><!--//container_area-->
</div>
	<!-- contents e -->
<jsp:include page="../include/footer.jsp" />